const { defineConfig } = require('@vue/cli-service')
const path = require('path')
const CompressionPlugin = require('compression-webpack-plugin') // Gzip 压缩

// 网站title
const websiteTitle = process.env.VUE_APP_TITLE || 'ASAN'
// 端口
const PORT = process.env.PORT || 85

module.exports = defineConfig({
  publicPath: '/zymanage/', // 如果不设置，则nginx部署后会去 xxx.xx.xx.xx/css/xx.css 去找，如果设置了publicPath，则去xxx.xx.xx.xx/admin/css/xx.css
  lintOnSave: false,
  transpileDependencies: true,
  pluginOptions: {
    'style-resources-loader': {
      preProcessor: 'less',
      patterns: [
        path.resolve(__dirname, './src/styles/common.less'),
        path.resolve(__dirname, './src/styles/variation.less')
      ]
    }
  },
  pwa: {
    iconPaths: {
      favicon32: 'logo.png',
      favicon16: 'logo.png',
      appleTouchIcon: 'logo.png',
      maskIcon: 'logo.png',
      msTileImage: 'logo.png'
    }
  },
  chainWebpack: (config) => {
    config.resolve.alias.set('#', path.resolve(__dirname, './src/types'))
    config.plugin('html').tap(args => {
      args[0].title = 'Awesome Web'
      return args
    })
  },
  configureWebpack: {
    // 网站title
    name: websiteTitle,
    // 插件配置
    plugins: [
      // http://doc.ruoyi.vip/ruoyi-vue/other/faq.html#使用gzip解压缩静态文件
      new CompressionPlugin({
        test: /\.(ts|css|html|js)?$/i, // 压缩文件格式
        filename: '[path][base].gz', // 压缩后的文件名
        algorithm: 'gzip', // 使用gzip压缩
        threshold: 10240, // 最小文件开启压缩
        minRatio: 0.8 // 压缩率小于1才会压缩
      })
    ]
  },
  devServer: {
    host: '127.0.0.1',
    port: PORT,
    open: true, // 编译完成立即打开
    hot: true,
    client: {
      progress: true,
      overlay: false
    }
  }
})
